package opn.srn.command;

import opn.srn.common.Factory;

public class CommandFactory extends Factory<String, String, ICommand<?>> {

	private static CommandFactory instance = new CommandFactory();

	public static CommandFactory get() {
		return instance;
	}

	@SuppressWarnings("unchecked")
	@Override
	public ICommand<?> newInstance(String key) throws Exception {
		String className = factory.get(key);
		if (className == null) {
			throw new Exception("Command by name '" + key + "' not registered...");
		}

		Class<ICommand<?>> commandClass = (Class<ICommand<?>>) Class.forName(className);
		return commandClass.newInstance();
	}

}
